﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;

namespace BusinessLayer
{
    public class ProductBL
    {
        /// <summary>
        /// Getting all products that are stored in the databse
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Common.Product> GetAllProducts()
        {
            return new ProductRepository().GetAllProducts();
        }

        /// <summary>
        /// Searching a product with the parameters specifed
        /// </summary>
        /// <param name="category"></param>
        /// <param name="name"></param>
        /// <param name="LeastPrice"></param>
        /// <param name="MaxPrice"></param>
        /// <returns></returns>
        public IEnumerable<Common.Product> Search(int category, string name, int LeastPrice, int MaxPrice)
        {
            return new ProductRepository().SearhProduct(category, name, LeastPrice, MaxPrice);
        }

        /// <summary>
        /// Updating the selected product details
        /// </summary>
        /// <param name="p"></param>
        public void AddProduct(Common.Product p)
        {
            new ProductRepository().AddProduct(p);
        }

        /// <summary>
        /// Updating the selected product details
        /// </summary>
        /// <param name="p"></param>
        public void UpdateProduct(Common.Product p)
        {
            new ProductRepository().UpdateProduct(p);
        }

        /// <summary>
        /// Getting the product details of the product that has the same selected ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Common.Product GetProductByID(int id)
        {
            return new ProductRepository().GetProductByID(id);
        }

        /// <summary>
        /// Adding the Products to a shopping cart
        /// </summary>
        /// <param name="t"></param>
        public void AddToCart(string username, int productID, int quantity)
        {
            new CartRepository().AddtoCart(username, productID, quantity);
        }

        /// <summary>
        /// Getting all catgeories from the database
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Common.Category> GetAllCategories()
        {
            return new ProductRepository().GetAllCategories();
        }

        /// <summary>
        /// Getting all item of the user shopping cart
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public List<Common.Cart> GetItemsInShoppingCart(string username)
        {
            return new CartRepository().GetUserNameCart(username).ToList();
        }

        /// <summary>
        /// Adding the product detail of the product bought
        /// </summary>
        /// <param name="od"></param>
        public void AddOrderDetails(Common.OrderDetail od)
        {
            new OrderReposity().AddOrderDetail(od);
        }

        /// <summary>
        /// Removing a product from the user shopping cart
        /// </summary>
        /// <param name="Id"></param>
        public void RemoveProductFromCart(int Id)
        {
            new CartRepository().RemoveProductFromCart(Id);
        }

        /// <summary>
        /// Getting the number of item there is in a username Cart
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public int GetNoOfItemsInShoppingCart(string username)
        {
            return new CartRepository().GetNoOfItemsInShoppingCart(username);
        }

        /// <summary>
        /// Adding and Order under the respective username when items are bought 
        /// </summary>
        /// <param name="O"></param>
        public void AddOrder(Common.Order O)
        {
            new OrderReposity().AddOrder(O);
        }

        /// <summary>
        /// Deleting a Record from the shopping cart
        /// </summary>
        /// <param name="id"></param>
        public void DeleteCart(int id)
        {
            new CartRepository().DeleteCart(id);
        }

        /// <summary>
        /// Getting all Products that the user bought
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public IEnumerable<Common.Product> GetAllUserProducts(string username)
        {
            return new ProductRepository().GetAllUserProducts(username);
        }

        /// <summary>
        /// Getting all Orders Gettings
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Common.OrderDetail> GettAllOrdersDetails()
        {
            return new OrderReposity().GettAllOrdersDetails();
        }

        /// <summary>
        /// Getting and order by its ID
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Common.Order GetOrderByID(Guid ID)
        {
            return new OrderReposity().GetOrderByID(ID);
        }
        /// <summary>
        /// Getting an order detail by its ID
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Common.OrderDetail GetOrderDetailByID(int id)
        {
            return new OrderReposity().GetOrderDetailByID(id);
        }

        /// <summary>
        /// Getting All the order Details of a particular Order
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IEnumerable<Common.OrderDetail> GetOrderDetailByOrderID(Guid id)
        {
            return new OrderReposity().GetOrderDetailByOrderID(id);
        }

        /// <summary>
        /// Getting All Orders that the user have made
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public IEnumerable<Common.Order> GetAllOrderByUserName(string username)
        {
            return new OrderReposity().GetAllOrderByUserName(username);
        }

        /// <summary>
        /// Getting all Items that the user have purchased using a view and includes Faults
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public IEnumerable<Common.Views.UserItem> GetUserProducts(string username)
        {
            return new ProductRepository().GetUserProducts(username);
        }
    }
}
